# FROM maven:3.5.0-jdk-8-alpine AS builder
# FROM mymaven:3.5.0-jdk-8-alpine AS builder
# 多阶段构建需要docker-17.05之后的版本。18版本构建会出现找不到文件
# FROM registry.cn-shanghai.aliyuncs.com/daqiantest/mymaven:3.5.0-jdk-8-alpine AS builder
FROM registry.cn-shanghai.aliyuncs.com/daqiantest/maven:maven AS builder

ADD ./settings.xml /usr/share/maven/conf/settings.xml
COPY chance-springcloud-client-demo        /opt/app/chance-springcloud-client-demo
COPY chance-springcloud-client-demo2       /opt/app/chance-springcloud-client-demo2
COPY chance-springcloud-config-server      /opt/app/chance-springcloud-config-server
# COPY chance-springcloud-discover-common    /opt/app/chance-springcloud-discover-common
COPY chance-springcloud-eureka             /opt/app/chance-springcloud-eureka
COPY chance-springcloud-gateway            /opt/app/chance-springcloud-gateway
COPY chance-springcloud-oauth2-server      /opt/app/chance-springcloud-oauth2-server
COPY chance-springcloud-zipkin             /opt/app/chance-springcloud-zipkin

WORKDIR /opt/app
RUN mvn clean package -Dmaven.test.skip=true && ls

RUN mkdir target
RUN ls

RUN cp /opt/app/chance-springcloud-client-demo/target/chance-springcloud-client-demo-0.0.1-SNAPSHOT.jar ./target
RUN cp /opt/app/chance-springcloud-client-demo2/target/chance-springcloud-client-demo2-0.0.1-SNAPSHOT.jar ./target
RUN cp /opt/app/chance-springcloud-config-server/target/chance-springcloud-config-server-0.0.1-SNAPSHOT.jar ./target
# RUN cp /opt/app/chance-springcloud-discover-common/target/-0.0.1-SNAPSHOT.jar ./target
RUN cp /opt/app/chance-springcloud-eureka/target/chance-springcloud-eureka-0.0.1-SNAPSHOT.jar ./target
RUN cp /opt/app/chance-springcloud-gateway/target/chance-springcloud-gateway-0.0.1-SNAPSHOT.jar ./target
RUN cp /opt/app/chance-springcloud-oauth2-server/target/chance-springcloud-oauth2-server-0.0.1-SNAPSHOT.jar ./target
RUN cp /opt/app/chance-springcloud-zipkin/target/chance-springcloud-zipkin-0.0.1-SNAPSHOT.jar ./target

RUN ls ./target

From openjdk:8-jre-alpine

ARG JAVA_OPTS
ENV JAVA_OPTS=$JAVA_OPTS
ENV JAR_NAME=$JAR_NAME

WORKDIR /opt/app/
COPY --from=builder /opt/app/target/* ./

ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar $JAR_NAME